package com.itheima.array;

import java.util.Scanner;

public class ArrayTest03 {
    /*
        定义一个数组,键盘录入数组中的具体数据,将数值存储到数组中,并求和
    */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sum = 0; // 定义一个求和变量
        int[] arr = new int[5];
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个整数");
            int num = sc.nextInt();
            if(num >= 50 && num <= 100){
                arr[i] = num;
            }else{
                System.out.println("输入的数据有误");
                i--; // 循环回退的应用
            }
        }

        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println("sum = " + sum);
    }
}
